<?php
	include("include/config.php");
	session_start();
?>

			<table border=1 style="display:inline-block;">
				<tr><th> Tên sản phẩm </th>
				<th> Đơn giá </th>
				<th> Số lượng </th>
				<th> Thành tiền </th>
				<th> Thao tác </th>
				</tr>
<?php
	if(isset($_SESSION['cart']))
	{
		$item = $_SESSION['cart'];
		 // var_dump($item);
		if(isset($_REQUEST["edit"])) {
				$id=$_POST["id"];
				$soluong=$_POST["soluong"];
				$item[$id]=$soluong;
				$_SESSION['cart'] = $item;
		}
		if(isset($_REQUEST["del"])) {
				$id=$_POST["id"];
				unset($item[$id]);
				$_SESSION['cart'] = $item;
		}


		$ids= array_keys($item);
		$id = implode(",", $ids);
		
		$sql="SELECT * FROM product WHERE id in($id)";
		$rs=mysql_query($sql);
		if($rs) 
		{
			$tong=0;
		  	while($rw=mysql_fetch_array($rs))  
		  	{
?>
				<form action="" method="post" name="update">	
				<tr>
					<td><?php echo $rw["name"];?></td>
					<td><?php echo number_format($rw["price"],0,',','.');?></td>
					<td><input type="text" value="<?php echo $item[$rw["id"]]; ?>" size="5" name="soluong"></td>
					<td><?php echo number_format($item[$rw["id"]]*$rw["price"],0,',','.');?></td>
					<td><input type="hidden" value="<?php echo $rw["id"]?>" name="id">
						<input name="edit" type="submit" value="Sửa"><input name="del" type="submit" value="Xóa">
					</td>
					<?php $tong=($tong+($rw["price"])*($item[$rw["id"]])); ?>
				</tr>
				</form>

<?php	
			}  	
				
?>
			<tr>
				<td><b>Tổng cộng:</b></td>
				<td></td>
				<td></td>
				<td><font color='red'><b><?php echo number_format($tong,0,',','.'); ?></b></font></td>
				<td><a href="thanhtoan.php"><img src="images/thanhtoan.png" /></a></td>
			</tr>

<?php	
		}
	}

?>	
		</table>